<template>
	<view class="content">
		<image mode="widthFix"
			src="https://img.meituan.net/msmerchant/844e1e7858cdf4fbced2e7b6974b9c8e161173.jpg@600w_600h_1l"
			class="top-bg"></image>
		<view class="detail-block">
			<view class="info-block">
				<image mode="aspectFill" :src="data.picUrl" class="photo"></image>
				<view class="info">
					<view class="name">{{data.title?data.title:''}}</view>
					<view class="score-block">
						<view class="score">{{data.score?data.score:''}}</view>
						<view class="capite">￥{{data.perPrice?data.perPrice:''}}</view>
						<view class="selling-season">季售{{data.sold?data.sold:''}}</view>
					</view>
					<view class="category-block">
						<view class="category">{{data.shopDsc?data.shopDsc:''}}</view>

					</view>
					<view class="ranking-block">
						<view class="ranking">酒泉人气排行第{{data.shopList?data.shopList:''}}</view>
					</view>
				</view>
			</view>
			<view class="business-hours">
				<view class="date">营业时间：{{data.startTime}}:00-{{data.endTime}}:00</view>
			</view>
			<view class="position-block">
				<view class="position">
					<view class="iconfont icon-dingweixiao"></view>{{data.other}}
				</view>
				<view class="navigator-block" @click="openMap">
					<view class="iconfont icon-daohang"></view>
					<view class="label">到这去</view>
				</view>
			</view>
		</view>
		<view class="title">套餐</view>
		<view class="list-block">
			<view hover-class="none" v-for="(item,index) in data.goods" :key="item.id" class="list-item">
				<image :src="item.picUrl" mode="aspectFill" class="photo"></image>
				<view class="info-block">
					<view class="name">{{item.setMealName?item.setMealName:''}}</view>
					<view class="other">{{item.detail?item.detail:''}}</view>
					<view class="price-block">
						<view class="discount-prices">￥{{item.discountPrice?item.discountPrice:''}}
							<!-- {{item.discountPrices}} -->
						</view>
						<view class="original-price">￥{{item.oldPrice?item.oldPrice:''}}</view>
					</view>
				</view>
				<view class="booking-block">
					<view class="booking-btn btn1" @click="advance(index)">预订</view>
					<view class="sold">已售{{item.sold}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getSnackByShopId,
		postReserve
	} from '@/api/food.js';
	export default {
		data() {
			return {
				data: {
					goods: []
				}
			}
		},
		onLoad(e) {
			console.log(e)
			this.id = e.id
			this.getTicketList()
		},
		methods: {
			openMap() {
				uni.openLocation({
					longitude: this.data.longitude,
					latitude: this.data.latitude,
					name: this.data.title,
					address: this.data.other,
				})
			},
			getTicketList() {
				let id = this.id
				getSnackByShopId({
					id
				}).then((res) => {

					if (res.code == 1) {
						if (res.data != null) {
							this.data = res.data;
							this.data.goods = res.data.setMeal
							console.log(11111)
							console.log(this.data.goods)
						}
					} else {
						console.log(res)
					}
				}).catch((res) => {
					console.log(res)
				})
			},
			//预定
			getList(e) {
				console.log(e)
				postReserve({
					orderType: 2,
					tid: 0,
					sid: this.data.goods[e].id,
					hid: 0,
					count: 0,
					price: this.data.goods[e].discountPrice,
					useDate: ''
				}).then((res) => {
					console.log(res)
					if (res.code == 1) {
						uni.showToast({
							title: '预定成功',
							mask: true,
						})
					} else {
						uni.showToast({
							title: '加载失败',
							mask: true,
						})
					}
				}).catch((res) => {
					uni.hideLoading();
					uni.showToast({
						title: '加载失败',
						mask: true,
					})
				})
			},
			advance(e) {
				this.getList(e)
			}
		},
		mounted() {

		}
	}
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: column;
		background: #F4F4F4;
		min-height: 100vh;

		.top-bg {
			width: 100%;
			height: auto;
			filter: blur(5px);
		}

		.detail-block {
			position: relative;
			border-radius: 5px;
			background: #fff;
			width: calc(100% - 80rpx);
			margin: 0 auto;
			margin-top: -120rpx;
			padding: 30rpx;
			padding-bottom: 0;
			display: flex;
			flex-direction: column;

			.info-block {
				display: flex;
				flex-direction: row;
				padding-bottom: 30rpx;
				border-bottom: 1px solid #efefef;

				.photo {
					width: 180rpx;
					height: 180rpx;
					border-radius: 10rpx;
					margin-right: 20rpx;
				}

				.info {
					width: calc(100% - 200rpx);
					display: flex;
					flex-direction: column;
					padding-bottom: 10rpx;

					.name {
						font-size: 34rpx;
						font-weight: bold;
					}

					.score-block {
						display: flex;
						align-items: center;
						margin-top: 4rpx;

						.score {
							flex-grow: 0;
							font-size: 34rpx;
							font-weight: bold;
							margin-right: 14rpx;
							background: url('@/static/bottom.png') no-repeat;
							background-position: center 85%;
							background-size: 80%;
						}

						.capite {
							flex-grow: 0;
							font-size: 26rpx;
							color: $color-secondary-text;
						}

						.selling-season {
							flex-grow: 1;
							font-size: 26rpx;
							color: $color-secondary-text;
							text-align: right;
						}
					}

					.category-block {
						display: flex;
						align-items: center;
						font-size: 24rpx;
						color: $color-secondary-text;
						margin-top: 4rpx;

						.category {
							flex-grow: 0;
							margin-right: 10rpx;
						}

						.business-area {
							flex-grow: 0;
						}

						.position {
							flex-grow: 1;
							display: flex;
							flex-direction: row;
							align-items: center;
							justify-content: flex-end;

							.iconfont {
								margin-right: 10rpx;
							}
						}
					}

					.ranking-block {
						display: flex;
						margin-top: 4rpx;

						.ranking {
							font-size: 24rpx;
							background: #FCF5E1;
							color: #dba81c;
							padding: 0 4rpx;
							border-radius: 8rpx;
						}
					}
				}
			}

			.business-hours {
				border-bottom: 1px solid #efefef;
				display: flex;
				flex-direction: row;
				align-items: center;
				height: 80rpx;
				font-size: 28rpx;

				.date {
					font-weight: bold;
					flex-grow: 1;
				}
			}

			.position-block {
				display: flex;
				flex-direction: row;
				align-items: center;
				font-size: 28rpx;
				height: 120rpx;

				.position {
					display: flex;
					flex-grow: 1;
					align-items: center;

					.iconfont {
						margin-right: 8rpx;
					}
				}

				.navigator-block {
					flex-grow: 0;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					font-size: 24rpx;

					.iconfont {
						background: #efefef;
						font-size: 34rpx;
						border-radius: 50%;
					}
				}
			}
		}

		.title {
			width: calc(100% - 80rpx);
			margin: 20rpx auto;
			font-weight: bold;
			border-left: 3px solid $color-primary;
			font-size: 32rpx;
			height: 34rpx;
			padding-left: 20rpx;
			display: flex;
			align-items: center;
		}

		.list-block {
			width: calc(100% - 80rpx);
			margin: 0 auto;
			display: flex;
			flex-direction: column;

			.list-item {
				display: flex;
				flex-direction: row;
				padding: 30rpx;
				background: #fff;
				border-bottom: 1px solid #efefef;
				margin-bottom: 20rpx;
				border-radius: 10rpx;

				.photo {
					width: 180rpx;
					height: 180rpx;
					border-radius: 10rpx;
					margin-right: 20rpx;
				}

				.info-block {
					width: calc(100% - 320rpx);
					display: flex;
					flex-direction: column;

					.name {
						font-weight: bold;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					.other {
						font-size: 26rpx;
						color: $color-secondary-text;
						margin: 20rpx 0;
					}

					.price-block {
						display: flex;
						flex-direction: row;
						align-items: center;

						.discount-prices {
							font-weight: bold;
							color: $color-danger;
						}

						.original-price {
							text-decoration: line-through;
							font-size: 24rpx;
							color: $color-secondary-text;
						}
					}
				}

				.booking-block {
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;

					.booking-btn {
						width: 120rpx;
						height: 60rpx;
						font-size: 28rpx;
					}

					.sold {
						margin-top: 20rpx;
						display: flex;
						flex-direction: row;
						font-size: 24rpx;
						color: $color-secondary-text;
					}
				}
			}

			.list-item:last-child {
				margin-bottom: 0;
				border-bottom: none;
			}
		}
	}
</style>
